package symbol;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

public class MethodTable {
        private String returnType;
        private List<String> parametersType = new ArrayList<String>();
        private HashMap<String, String> varsType = new HashMap<String, String>();
        private String methodName;

        @Override
        public String toString() {
                String r = new String();
                r += returnType + " ";
                r += methodName + " ( ";
                for(int i = 0; i < parametersType.size() ; i++ ) {
                        r+= parametersType.get(i);
                        r+= " ";
                }
                r+= ")";
                Set<String> hs = varsType.keySet();
                r+=" {\n";
                for(String key : hs) {
                        r+=varsType.get(key) + " " + key + " ;\n";
                }
                r+="}";
                r+="\n";
                return r;               
        }

        public void setReturnType(String r) {
                returnType = r;
        }

        public String getReturnType() {
                return returnType;
        }

        public boolean addParameterType(String p, String name) {
                parametersType.add(p);
                if (varsType.containsKey(p))
                        return false;
                varsType.put(name, p);
                return true;
        }

        public String getParameterType(int n) {
                return parametersType.get(n);
        }

        public String getParameterType(String id) {
                return parametersType.get(parametersType.indexOf(id));
        }

        public int getParameterSize() {
                return parametersType.size();
        }

        public boolean addVar(String id, String type) {
                if (varsType.containsKey(id))
                        return false;
                varsType.put(id, type);
                return true;
        }

        public String getVarType(String id) {
                return varsType.get(id);
        }

        public boolean containsVar(String id) {
                return varsType.containsKey(id);
        }

        public boolean containsParameter(String id) {
                return parametersType.contains(id);
        }

        public void setMethodName(String methodName) {
                this.methodName = methodName;
        }

        public String getMethodName() {
                return methodName;
        }

}